<!--
- Author:   .
- Date:    2018/2/2 0002.
- File:    花链钱币转积分.
-->
<template>
  <div>
    <div class="tits">你的花链钱币：<span class="cr_f83166">{{walletInfo.balance}}&nbsp;&nbsp;(1钱币 = 1积分)</span></div>
    <div class="Withdrawals">
      <ul>
        <li><label><span class="nim">兑换数量</span><input type="tel" placeholder="请输入兑换数量" v-model="amount"></label></li>
      </ul>
    </div>
    <p class="tistext2">可兑换积分：{{amount}}</p>
    <p class="tistext2"></p>
    <div class="pl20 pr20 mt35">
      <a href="" class="but_1 wauto disb tc" @click="transfer">确认兑换</a>
    </div>
  </div>
</template>

<script>
  import {mapModules, mapRules} from 'vuet'

  export default{
    mixins: [
      mapModules({memberInfo: 'memberInfo', walletInfo: 'walletInfo'}),
      mapRules({need: ['memberInfo', 'walletInfo']})
    ],
    data() {
      return {
        amount: ''
      }
    },
    created() {
      this.getWalletInfo()
    },
    components: {},
    watch: {
      amount: function (newValue) {
        if (newValue == '') {
          return
        }
        if (parseFloat(newValue) > parseFloat(this.walletInfo.balance)) {
          this.$toast('超出了最大可用花链钱币')
          this.amount = this.walletInfo.balance
        }
      }
    },
    methods: {
      transfer() {
        this.$request.wallet2Integral(this.amount).then(data => {
          this.$toast('兑换成功')
          this.$router.push({name: 'my'})
        }).catch(e => {
          this.$toast('兑换失败')
          console.error('花链钱币兑换失败', e)
        })
      }
    }
  }
</script>

<style>

</style>